$(document).ready(function(){
	$(document).ready(function() {
		$('.carou').carouFredSel({
			items               : 3,
			direction           : "down",
			scroll : {
				items           : 1,
				effect          : "easeOutBounce",
				duration        : 400,                        
				pauseOnHover    : true
			}
		});
	});

	$('#btnlogin').click(function(){
		if($("#login-form").is(":hidden"))
			$("#login-form").slideDown("slow");	
		else
			$("#login-form").slideUp("slow");
	});		
	$('#btngooglemap').click(function(){
		if($(this).is(':checked'))
			$("#googlemapinfo").slideDown("slow");	
		else{
			$("#googlemapinfo").slideUp("slow");
		}
	});
	$('#startretailshop').click(function(){
		var country_select =  $('#country_select').val();
		var category_select =  $('#category_select').val();
		var city_select =  $('#city_select').val();
		var brand_select =  $('#brand_select').val();		
		var find_cityname =  $('#find_cityname').val();		
		
		if(country_select != -1 || category_select != -1 || city_select!= -1 || brand_select != '' || find_cityname != '')
		{
			$.ajax({
			 url:"index.php?option=com_retailshop&view=home&task=search",
			 data:{country_select:country_select, category_select:category_select, city_select:city_select, brand_select:brand_select, find_cityname:find_cityname},
			 type: "POST",
			 dataType: "html",
			 success:function(data) {
				if(data == -1) {
					alert("errors in processing");
				}else   {
					$("#list_result").html(data);
				}
			}
			});
		}
		
	});
	
	$('#toolbar-edit').click(function(){				
		var input = $('input:checkbox[name="ckbproduct[]"]:checked');		
		if(input.length == 1){
			var id = $('input:checkbox:checked').val();			
			var url = 'index.php?option=com_retailshop&view=myshop&task=addnew&id=' + id;			
			location.href = url;
			return false;			
		}else{
			alert('Please select one product, Thank you!');
			return false;
		}		
	});
	$('#toolbar-edit-slideshow').click(function(){				
		var input = $('input:checkbox[name="slideshow[]"]:checked');		
		if(input.length == 1){
			var id = $('input:checkbox:checked').val();			
			var url = 'index.php?option=com_retailshop&view=myshop&task=editslideshow&id=' + id;			
			location.href = url;
			return false;			
		}else{
			alert('Please select one slideshow, Thank you!');
			return false;
		}		
	});
	$('#toolbar-edit-catagory').click(function(){				
		var input = $('input:checkbox[name="catelog[]"]:checked');		
		if(input.length == 1){
			var id = $('input:checkbox:checked').val();			
			var url = 'index.php?option=com_retailshop&view=myshop&task=editcatelogy&id=' + id;			
			location.href = url;
			return false;			
		}else{
			alert('Please select one catagory, Thank you!');
			return false;
		}		
	});
	
	$('#toolbar-edit-event').click(function(){				
		var input = $('input:checkbox[name="ckbevent[]"]:checked');
		if(input.length == 1){
			var id = $('input:checkbox:checked').val(); 			
			var url = "index.php?option=com_retailshop&view=myshop&task=editevnet&id=" + id;			
			location.href = url;
			return false;			
		}else{
			alert('Please select one event, Thank you!');
			return false;
		}		
	});
	
	$('#toolbar_delete_product').click(function(){		
		var input = $('input:checkbox[name="ckbproduct[]"]:checked');		
		if(input.length == 1){
			var id = $('input:checkbox:checked').val(); 						
			var url = 'index.php?option=com_retailshop&view=myshop&task=delete&name=product&id=' + id;						
			location.href = url;			
			return false;
		}else{
			alert('Please select one product, Thank you!');
			return false;
		}	
			
	});
	$('#toolbar-delete-catagory').click(function(){		
		var input = $('input:checkbox[name="catelog[]"]:checked');			
		if(input.length == 1){
			var id = $('input:checkbox:checked').val(); 						
			var url = 'index.php?option=com_retailshop&view=myshop&task=delete&name=catelogy&id=' + id;			
			location.href = url;			
			return false;
		}else{
			alert('Please select one catelogy, Thank you!');
			return false;
		}	
			
	});
	$('#toolbar-delete-slideshow').click(function(){		
		var input = $('input:checkbox[name="slideshow[]"]:checked');			
		if(input.length == 1){
			var id = $('input:checkbox:checked').val();			
			var url = 'index.php?option=com_retailshop&view=myshop&task=delete&name=slideshow&id=' + id;			
			location.href = url;			
			return false;
		}else{
			alert('Please select one slideshow, Thank you!');
			return false;
		}	
			
	});
	
	$('#toolbar-delete-event').click(function(){
		var input = $('input:checkbox[name="ckbevent[]"]:checked');
		if(input.length == 1){
			var id = $('input:checkbox:checked').val(); 			
			var url = 'index.php?option=com_retailshop&view=myshop&task=delete&name=event&id=' + id;			
			location.href = url;
			return false;
		}else{
			alert('Please select one event, Thank you!');			
			return false;
		}	
			
	});
	

	$("#find-shop").click(function(){		
		var country_select =  $('#country_select').val();
		var category_select =  $('#category_select').val();
		var city_select =  $('#city_select').val();
		var brand_select =  $('#brand_select').val();		
		
		if(country_select != -1 || category_select != -1 || city_select!= -1 || brand_select != '')
		{
			$.ajax({
			 url:"index.php?option=com_retailshop&view=home&task=search",
			 data:{country_select:country_select, category_select:category_select, city_select:city_select, brand_select:brand_select},
			 type: "POST",
			 dataType: "html",
			 success:function(data) {
				if(data == -1) {
					alert("errors in processing");
				}else   {
					$("#list_result").html(data);
				}
			}
			});
		}
	});
	$("#btnsearchshop").click(function(){		
		var country_select =  $('#country_').val();
		var category_select =  $('#category_').val();
		var city_select =  $('#city_').val();
		var brand_select =  $('#brand_').val();
		var url = 'index.php?option=com_retailshop&view=home&task=findthelocalfreashop&country='+country_select+'&category='+category_select+'&city='+city_select+'&brand='+brand_select;
		location.href = url;
		return false;
	});
	
	$('#btnimageaddnew').click(function(){
		var curent = $('#retaishop-image').html();
		var newslide = '';
		$('#retaishop-image').html(curent + curent);
		return false;
	});
	
	$("#country_select").change(function(){
		var country_id =  $(this).val();
		if(country_id != -1)
		{
			$.ajax({
				url:"index.php?option=com_retailshop&view=home&task=listcity",
				data:{country_id:country_id},
				type: "POST",
				dataType: "html",
				success:function(data) {
					if(data == -1) {
						alert("errors in processing");
					}else   {
						$("#city_select").html(data);
					}
				}
			});
		}else{
			$("#city_select").html('<option value="-1"> --- Please Select --- </option>');
		}
	});
});

	function loadCityForContry(country)
	{	
		var country_id = country.id;
		var arr = country_id.split("_");
		var id = arr[2];
		var city_id = "city_select_" + id;
		
		var country_value = country.value;		
		country_select(country_value,city_id);
	}
	
	function country_select(country_id,city_id,select_id){		
		jQuery.ajax({				
				url:"index.php?option=com_retailshop&view=home&task=listcity",
				data:{country_id:country_id, select_id:select_id},
				type: "POST",
				dataType: "html",
				success:function(data) {					
					if(data == -1) {
						return false;
					}else  
					{
						var city = document.getElementById(city_id);
						city.innerHTML = data;
					}
				}
		});
	}